<title>后台管理员</title>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>用户</cite></a>
    <a><cite>关于我们</cite></a>
  </div>
</div>

<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <table class="layui-hide" id="table-instance" lay-filter="table-instance"></table>
        <script type="text/html" id="table-useradmin-webuser">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                </script>
      </div>
    </div>
  </div>
</body>
<script>
  layui.use(['layedit', 'admin', 'upload', 'laydate', 'useradmin', 'table', 'form'], function () {
    var $ = layui.$,
      $ = layui.jquery,
      admin = layui.admin,
      setter = layui.setter,
      view = layui.view,
      table = layui.table,
      form = layui.form,
      leyer = layui.leyer,
      upload = layui.upload,
      laydate = layui.laydate,
      layedit = layui.layedit;

    form.render(null, 'layadmin-userfront-formlist');

    //监听搜索
    form.on('submit(LAY-user-front-search)', function (data) {
      var field = data.field;

      //执行重载
      table.reload('table-instance', {
        where: field
      });
    });

    table.render({
      elem: "#table-instance",
      url: setter.request.baseUrl + "/ours/frontend/info",
      method: "get",
      headers: {
        token: layui.data("layuiAdmin").token
      },
      response: {
        statusName: "code",
        statusCode: 0,
        msgName: "msg",
        countName: "count",
        dataName: "list",
      },
      // where: {
      //     typeId: 1
      // },       //传给后端的数据
      cols: [
        [{
          field: "partnerId",
          width: "6%",
        }, {
          field: "partnerName",
          width: "6%",
          align: 'center',
          title: "名称",
          sort: true
        }, {
          field: "partnerLogo",
          width: "37%",
          align: 'center',
          title: "公司logo"
        }, {
          field: "url",
          width: "9%",
          align: 'center',
          title: "官方链接"
        }, {
          align: 'center',
          title: "手动操作",
          width: "7%",
          toolbar: "#table-useradmin-webuser" //删除、编辑
        }]

      ],
      page: true, //分页
    });
    $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    //删除模块
    table.on("tool(table-instance)", function (obj) {
      var data = obj.data;

      if (obj.event === "del") {
        layer.confirm("真的删除么", function (index) {
          delAdminHandle({
            partnerId: data.partnerId, //接口参数
          });

          obj.del();
          layer.close(index);
        });
      } else if (obj.event === "edit") {
        admin.popup({
          title: "编辑合作伙伴",
          area: ["400px", "400px"],
          success: function (layero, index) {

            view(this.id)
              .render("user/administrators/orderform", data)
              .done(function () {
                let _data = data;
                form.render(null, "layuiadmin-form-admin");
              });
          },
        });
      }

    });
    //删除
    function delAdminHandle(params) {
      console.log(params)

      //  debugger
      admin.req({
        //*****************需要替换****************
        url: setter.request.baseUrl + "/partner/admin/delete",
        data: {
          ...params,
        },
        type: "post",
        done: function (res) {
          layer.msg("删除成功"); //删除成功之后弹窗
        },
      });
    }

    //修改编辑
    function editUserHandle(params) {
      admin.req({
        url: setter.request.baseUrl + "/partner/admin/save",
        data: JSON.stringify(params),
        type: "post",
        dataType: "json",
        contentType: "application/json",
        done: function (res) {
          layui.table.reload("table-instance");
        },
      });
    }

    admin.req({
      url: setter.request.baseUrl + "/ours/frontend/info",
      type: "get",
      done: function (res) { },

    });
  })
</script>
<!-- <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table-instance" lay-filter="table-instance"></table>
        </div>
    </div>
</div> -->
<!-- 团队管理图片 -->
<!-- <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>团队管理：图片上传</legend>
</fieldset>

<div class="layui-upload">
    <button type="button" class="layui-btn" id="test1">上传图片</button>
    <div class="layui-upload-list">
        <img class="layui-upload-img" id="demo1">
        <p id="demoText"></p>
    </div>
    <textarea name="" required lay-verify="required" placeholder="团队管理图片信息" class="layui-textarea"></textarea>
</div> -->

<!-- 上传荣誉资质图片 -->
<!-- <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>上传多张图片</legend>
</fieldset>

<div class="cont newDrugs">
    <div class="layui-upload">
        <button type="button" class="layui-btn" id="test2">多图片上传</button>
        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
            预览图：
            <div class="layui-upload-list" id="demo2"></div>
        </blockquote>
    </div>
    <textarea name="" required lay-verify="required" placeholder="荣誉描述" class="layui-textarea"></textarea>
</div> -->
<!-- <script>
        //单张图片上传
        var uploadInst = upload.render({
            elem: '#test1',
            url: setter.request.baseUrl + '/upload/admin/file' //改成您自己的上传接口
                ,
            before: function(obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            },
            done: function(res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            },
            error: function() {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function() {
                    uploadInst.upload();
                });
            }
        });



        //多图片上传
        upload.render({
            elem: '#test2',
            url: setter.request.baseUrl + '/upload/admin/file' //改成您自己的上传接口 
                ,
            multiple: true,
            before: function(obj) {
                //预读本地文件示例，不支持ie8
                console.log(obj)
                obj.preview(function(index, file, result) {
                    $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
                });
            },
            done: function(res) {
                //上传完毕
            }
        });

    })
</script> -->